import math
import numpy as np
import matplotlib.pyplot as plt
N = 64
dx = 2*math.pi/N
x = np.linspace(0,2*math.pi,N)
f = []
for i in x:
    f.append(math.cos(i))
dfdx = []
i=2
for i in range(np.size(x)-2):
    dfdx.append((math.cos(x[i+2])-math.cos(x[i]))/(2*dx))
df = 2*dfdx[0]-dfdx[1]
dfdx=[df]+dfdx
dfdx.append(2*dfdx[np.size(dfdx)-1]-dfdx[np.size(dfdx)-2])
plt.plot(x,np.array(dfdx),linestyle='--',color='r')
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Difference of cos(x)')
plt.show()